package senior.StringTest;

import java.util.Scanner;

/**
 * 1:输入两个字符串，查找第一个字符串在第二个字符串中出现的次数
 * 比如输入dog和 This is a good dog.
 * 则出现了一次。
 *
 * 从键盘输入一个字符串不允许输入空格,空格就表示一个字符串结束
 * @author shkstart
 * @creat 2022-04-14:12
 */
public class StringTest1 {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        System.out.println("输入字符串：");
        String s1 = sc.next();
        //String s1 = "kk";
        System.out.println("输入字符串：");
        String s2 = sc.next();
        //String s2 = "ssskssskksssk kdddddksskskk s";
//        String s3 = sc.next();
//        System.out.println(s1);
//        System.out.println(s2);
//        System.out.println(s3);

        int count = 0;
        int index = 0;

        while (s2.indexOf(s1,index) != -1){
            index = s2.indexOf(s1,index) + s1.length();
            count++;
        }

        System.out.println("出现次数:" + count + "次");

    }
}
